<?php
/**
 * Core_Data_Getaccesslevels
 * get access levels from database
 *
 * @author Adrian Stolarski
 */
class Core_Data_Getaccesslevels implements Core_Data_Mainable, 
        Core_Data_Preparable{
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    /**
     *
     * @var type $database_query
     * database query handler
     */
    public $database_query;
    /**
     * constructor()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    /**
     * main()
     * get access levels tab
     * 
     * @param array $variables
     * @return type $access_levels
     */
    public function main(array $variables = null) {
        //var_dump($variables);
        //die();
        $this->database->connect();
        $this->prepare_query($variables);
        //echo $this->database_query;
        //die();
        $this->database->prepare($this->database_query);
        $this->database->query();
        $access_levels = array();
        while($access_level_data = $this->database->fetch('array')){
            $access_levels[$access_level_data['access_level_name']] = array(
                'id' => $access_level_data['id'],
                'access_level_name' => $access_level_data['access_level_name']
            );
        }
        return $access_levels;
    }
    
    /**
     * preapre_query()
     * preapare database query
     * @param array $variables
     */
    public function prepare_query(array $variables = null) {
        $this->database_query = "SELECT * FROM access_level ORDER BY access_level_type ASC;";
    }

}
